package com.common.listener;


import com.common.log.LogAspect;
import com.common.vo.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.HashMap;
import java.util.Map;

/**
 * application 生命周期监听
 * @author YYQ
 *
 */
@WebListener
public class MyServletContextListener implements ServletContextListener {

	private final Logger logger = LoggerFactory.getLogger(MyServletContextListener.class);
	/** 登录限流*/
	public static Map<String, Object> loginMap = new HashMap<String, Object>();
	/** mqtt连接对象*/
	public static MqttMessage mqttMessage;


	@Override
	public void contextInitialized(ServletContextEvent sce) {

		logger.info("===================> 系统已启动");
		// 将热部署改为false
		//System.setProperty("spring.devtools.restart.enabled", "false");

		//ConfigService configService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(ConfigService.class);
		//MyServletContextListener.configService = configService;
		//mqttMessage = MqttMessage.getInstance();


	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {

		logger.info("===================> 系统已销毁");
		// 操作日志线程释放
		while(LogAspect.getQueue().size() == 0) {
			LogAspect.setRun(false);
			break;
		}

	}


	
}
